//
//  SEGDigitalCommunity2HouseInfoViewModel.m
//  Commom
//
//  Created by 山刘 on 2020/6/28.
//

#import "SEGDigitalCommunity2HouseInfoViewModel.h"

@interface SEGDigitalCommunity2HouseInfoViewModel()
@property (nonatomic, strong, readwrite) RACCommand *requestBuildingCommand;
@property (strong, nonatomic, readwrite) RACSubject *messageSubject;
@end

@implementation SEGDigitalCommunity2HouseInfoViewModel
#pragma mark - Init
-(instancetype)init{
    if (self = [super init]) {
        [self racInit];
    }
    return self;
}

-(void)dealloc{
    [self.requestBuildingCommand rac_deallocDisposable];
    [self.messageSubject rac_deallocDisposable];
}

- (void)racInit {

    @weakify(self);
    _requestBuildingCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
        return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
            @strongify(self);

            //请求查询项目下辖楼栋列表
            [self.myProfileManager requestBuildingListBycommunityId:kAccountCommunityID Finished:^(BOOL isSuccessed, NSString *codeType, NSString *errorMessage) {
                if (!isSuccessed) {
                    [self.messageSubject sendNext:errorMessage];
                }
                [subscriber sendNext:nil];
                [subscriber sendCompleted];
            }];

            return [RACDisposable disposableWithBlock:^{
            }];
        }];
    }];
}

#pragma mark - Publish Methods

#pragma mark - Private Methods

#pragma mark - Getter
-(RACSubject *)messageSubject{
    if (!_messageSubject) {
        _messageSubject = [RACSubject subject];
    }
    return _messageSubject;
}
- (SEGMyProfileManager *)myProfileManager {
    if (!_myProfileManager) _myProfileManager = [[SEGMyProfileManager alloc] init];
    return _myProfileManager;
}

#pragma mark - Stter
@end
